package com.zhkj.framework.controller;

import com.zhkj.framework.domain.Accounts;
import com.zhkj.framework.enums.ResultEnum;
import com.zhkj.framework.exception.CommonException;
import com.zhkj.framework.service.AccountsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: zhangy
 * @Date: 2018/10/29 14:28
 * @Description:
 */
@Slf4j
@Api(value = "科目接口",tags = "科目接口")
@RestController
public class AccountsController {

    @Autowired
    private AccountsService accountsService;

    //科目列表查询
    @ApiOperation(value = "科目查询，全部")
    @GetMapping("accounts")
    public List<Accounts> selectAccounts(){
        List<Accounts> accountsList = accountsService.selectAll();
        return accountsList;
    }

    @ApiOperation(value = "科目查询，按科目代码")
    @GetMapping("accountone")
    public List<Accounts> selectOnes(@ApiParam(value = "科目代码",name = "accountCode",required = true) @RequestParam("accountCode") String accountCode){
        if(accountCode == null || accountCode.length() == 0){
           throw new CommonException(ResultEnum.ACCOUNTS_IS_NOLL);
        }
        List<Accounts> accountsList = accountsService.selectOnes(accountCode);
        return accountsList;
    }

}
